﻿Imports GT = Gadgeteer
Imports GTM = Gadgeteer.Modules
Imports Gadgeteer.Modules.GHIElectronics



Namespace GadgeteerApp1


    Partial Public Class Program

        Dim whole As Integer
        Dim number As Integer
        Dim remainder As Integer
        Dim font As Font = Resources.GetFont(Resources.FontResources.NinaB)
        Dim WithEvents timer As GT.Timer = New GT.Timer(1000)  ' every second (1000ms)
        ' This is run when the mainboard is powered up or reset. 
        Public Sub ProgramStarted()

            ' Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started")
            display.SimpleGraphics.DisplayText(0.ToString(), font, GT.Color.Yellow, 50, 50)

        End Sub


        Private Sub button_ButtonPressed1(sender As Button, state As Button.ButtonState) Handles button.ButtonPressed

                If timer.IsRunning Then
                timer.Stop()
            Else
                timer.Start()
            End If
           

        End Sub

        Private Sub timer_Tick(timer As Gadgeteer.Timer) Handles timer.Tick
            number = number + 1
            Debug.Print(number.ToString())

            led_Strip.TurnAllLedsOff()
            ' display number

            display.SimpleGraphics.ClearNoRedraw()
            display.SimpleGraphics.DisplayText(number.ToString(), font, GT.Color.Yellow, 50, 50)
            whole = number \ 64
            remainder = number Mod 64

            If whole = 1 Then
                led_Strip(6) = True

            Else
                led_Strip(6) = False
            End If

            whole = remainder \ 32
            remainder = remainder Mod 32

            If whole = 1 Then
                led_Strip(5) = True
            Else
                led_Strip(5) = False
            End If

            whole = remainder \ 16
            remainder = remainder Mod 16
            If whole = 1 Then
                led_Strip(4) = True
            Else
                led_Strip(4) = False
            End If

            whole = remainder \ 8
            remainder = remainder Mod 8
            If whole = 1 Then
                led_Strip(3) = True
            Else
                led_Strip(3) = False
            End If

            whole = remainder \ 4
            remainder = remainder Mod 4
            If whole = 1 Then
                led_Strip(2) = True
            Else
                led_Strip(2) = False
            End If

            whole = remainder \ 2
            remainder = remainder Mod 2
            If whole = 1 Then
                led_Strip(1) = True
            Else
                led_Strip(1) = False
            End If
            whole = remainder \ 1
            remainder = remainder Mod 1
            If whole = 1 Then
                led_Strip(0) = True
            Else
                led_Strip(0) = False

            End If
             
        End Sub

        
    End Class
End Namespace
